<?php

namespace Topxia\WebBundle\Extensions\DataTag;

use Topxia\WebBundle\Extensions\DataTag\DataTag;

class QiniuTestDataTag extends BaseDataTag implements DataTag  
{
    public function getData(array $arguments)
    {   
        $time = time();
        $random = $this->random(6);
        $basename = $time.$random;
        $config['basename'] = $basename;
        $config['uptoken'] = $this->getQiniuService()->getUptoken($basename);
        //$config = $this->getQiniuService()->getUptoken('123');
        
        return $config;
    }

    protected function getQiniuService()
    {
        return $this->getServiceKernel()->createService('Qiniu.QiniuService');
    }

    protected function random($length)
    {
        $str = "abcdefghijklmnopqrstuvwxyz";//输出字符集
        $n = $length;//输出串长度
        $len = strlen($str)-1;
        for($i=0 ; $i<$n; $i++){
            $s .= $str[rand(0,$len)];
        }
        return $s;
    }
}